package org.me.adapter;

import java.util.ArrayList;

import org.jivesoftware.smack.util.StringUtils;
import org.me.R;
import org.me.R.id;
import org.me.R.layout;
import org.me.utils.Koneksi;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class Adapter_Message extends BaseAdapter{

	private int count;
	private Context context;
	private ArrayList<String> message;
	private String user;

	public Adapter_Message(Context context, ArrayList<String> message, String user)
	{
		this.count = message.size();
		this.context = context;
		this.message = message;
		this.user = user;
	}
	
	public void addItem(ArrayList<String> message1) {
    	this.message = message1;
    }

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return count;
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View contentView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		String name = StringUtils.parseName(Koneksi.getInstance().getConnection().getUser());

		if (name.equalsIgnoreCase(message.get(position).substring(0, user.length()))) {
			contentView = inflater.inflate(R.layout.list_row_layout_even, parent, false);
			TextView title = (TextView)contentView.findViewById(R.id.text);
			title.setText(message.get(position));
		}
		else {
			contentView = inflater.inflate(R.layout.list_row_layout_odd, parent, false);
			TextView title = (TextView)contentView.findViewById(R.id.text);
			title.setText(message.get(position));
		}
		
//		contentView = inflater.inflate(R.layout.multi_line_list_item, null);
//		TextView title = (TextView)contentView.findViewById(R.id.text1);
//		title.setText(message.get(position));

		return contentView;
	}

}
